import { WeaSearchGroup,WeaTools ,WeaErrorPage ,WeaFormItem , WeaLocaleProvider} from 'ecCom';
import { WeaSwitch } from 'comsMobx';
const getLabel = WeaLocaleProvider.getLabel;

class Condition extends React.Component{

    constructor(){
        super();
        this.formParams = {};
    }

    render(){
        const { condition, form } = this.props.queryStore;
        const {isFormInit} = form;
        let group = [];
        const formParamsTemp = form.getFormParams();
        for(let param in formParamsTemp){
            this.formParams[param] = formParamsTemp[param];
        }
        isFormInit && condition.map((c,index) =>{
            let items = [];
            c.items.map(fields => {
                items.push({
                    com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@n7oj39@${fields.domkey[0]}`}
                        label={`${fields.label}`}
                        labelCol={{span: `${fields.labelcol}`}}
                        wrapperCol={{span: `${fields.fieldcol}`}}>
                            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@wue3wf@${fields.domkey[0]}`} fieldConfig={fields} form={form} formParams={this.formParams} onEnterSearch={this.onEnterSearch}/>
                        </WeaFormItem>),
                    colSpan:1
                })
            });
            group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@i5iqmb@${index}`} needTigger={false} title={c.title} showGroup={c.defaultshow} items={items}/>)
        });
        return <div>{group}</div>;
    }

    onEnterSearch = () =>{
        const {getSessionkey,setShowSearchAd} = this.props.queryStore;
        getSessionkey();
        setShowSearchAd(false);
    }
}

export default WeaTools.tryCatch(React,
    props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@8c9r68`} msg={ props.error ? props.error : getLabel(383324,'对不起，该页面异常，请联系管理员！')} />,
    {error: ""}
)(Condition);
